package com.example.day09;

import com.example.day10.DBCPDatasource;
import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Insert {



    public static void main(String[] args) throws SQLException {
        // 1. Driver
        new Driver();
        // 2. Connection
        Connection connection = DBCPDatasource.getConnection();
        System.out.println(connection);

        String sql = "INSERT INTO db_test.student VALUES(NULL, ?, ?, ?)";

        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, "Jerry");
        preparedStatement.setInt(2, 17);
        preparedStatement.setString(3, "F");

        preparedStatement.executeUpdate();
    }
}
/*
mysql> create database db_test;
        Query OK, 1 row affected (0.00 sec)

        mysql> show databases;
        +--------------------+
        | Database           |
        +--------------------+
        | information_schema |
        | db_test            |
        | mysql              |
        | performance_schema |
        | sys                |
        +--------------------+
        5 rows in set (0.00 sec)

        mysql> create table db_test.student (
        -> id int auto_increment primary key,
        -> name varchar(255) not null,
        -> age int(2) ,
        -> gender char(1)
        -> );
        Query OK, 0 rows affected (0.28 sec)
*/